package com.supor.aiot.food.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;

import com.supor.aiot.food.R;
import com.supor.aiot.websocket.Logc;

import me.dkzwm.widget.srl.SmoothRefreshLayout;
import me.dkzwm.widget.srl.extra.IRefreshView;
import me.dkzwm.widget.srl.indicator.IIndicator;
import me.dkzwm.widget.srl.util.PixelUtl;

/**
 * @author: zook
 * @date: 2021/11/30
 */
public class JumpToVideoInfoLayout<T extends IIndicator> extends FrameLayout implements IRefreshView<T> {

    private Context context;
    private View rootView;

    public JumpToVideoInfoLayout(Context context) {
        this(context, null);
    }

    public JumpToVideoInfoLayout(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public JumpToVideoInfoLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context);
        this.context = context;
        rootView = View.inflate(context, R.layout.layout_jump_to_info, this);
//        rootView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
//        addView(rootView);
    }

    @Override
    public int getType() {
        return TYPE_FOOTER;
    }

    @Override
    public int getStyle() {
        return STYLE_DEFAULT;
    }

//    @Override
//    public int getCustomHeight() {
//        return PixelUtl.dp2px(getContext(), context.getResources().getDimensionPixelOffset(R.dimen.dp_415));
//    }
    @Override
    public int getCustomHeight() {
        return 0;
    }

    @NonNull
    @Override
    public View getView() {
        return this;
    }

    @Override
    public void onFingerUp(SmoothRefreshLayout layout, T indicator) {
        Logc.d("JumpToVideoInfoLayout_debug onFingerUp");
    }

    @Override
    public void onReset(SmoothRefreshLayout layout) {
        Logc.d("JumpToVideoInfoLayout_debug onReset");
    }

    @Override
    public void onRefreshPrepare(SmoothRefreshLayout layout) {
        Logc.d("JumpToVideoInfoLayout_debug onRefreshPrepare");
    }

    @Override
    public void onRefreshBegin(SmoothRefreshLayout layout, T indicator) {
        Logc.d("JumpToVideoInfoLayout_debug onRefreshBegin");
    }

    @Override
    public void onRefreshComplete(SmoothRefreshLayout layout, boolean isSuccessful) {
        Logc.d("JumpToVideoInfoLayout_debug onRefreshComplete");
    }

    @Override
    public void onRefreshPositionChanged(SmoothRefreshLayout layout, byte status, T indicator) {
        final int mOffsetToRefresh = indicator.getOffsetToLoadMore();
        final int currentPos = indicator.getCurrentPos();
        final int lastPos = indicator.getLastPos();
        Logc.d("JumpToVideoInfoLayout_debug onRefreshPositionChanged mOffsetToRefresh=" + mOffsetToRefresh + " currentPos=" + currentPos + " lastPos=" + lastPos);

        if (currentPos < mOffsetToRefresh && lastPos >= mOffsetToRefresh) {
            if (indicator.hasTouched() && status == SmoothRefreshLayout.SR_STATUS_PREPARE) {
//                mTitleTextView.setText(R.string.swipe_to_load_detail);
//                mRotateView.clearAnimation();
//                mRotateView.startAnimation(mReverseFlipAnimation);
            }
        } else if (currentPos > mOffsetToRefresh && lastPos <= mOffsetToRefresh) {
            if (indicator.hasTouched() && status == SmoothRefreshLayout.SR_STATUS_PREPARE) {
//                mTitleTextView.setText(R.string.release_to_load_detail);
//                mRotateView.clearAnimation();
//                mRotateView.startAnimation(mFlipAnimation);
            }
        }
    }

    @Override
    public void onPureScrollPositionChanged(SmoothRefreshLayout layout, byte status, T indicator) {
        Logc.d("JumpToVideoInfoLayout_debug onPureScrollPositionChanged");
    }
}
